﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Assist;
using YArchitech.Controls;
using YArchitech.LIB;
using RegionSplittor.Utils;

namespace HYLightingEquipmentLay.Forms
{
	public partial class FormSmokeDetectorConfig : System.Windows.Forms.Form
	{
		public FormSmokeDetectorConfig()
		{
			this.InitializeComponent();
			this.xmlHelper.LoadXml(this.path, this.Root);
			this.LoadDlgData();
		}

		private void radioButton1_CheckedChanged(object sender, EventArgs e)
		{
			if (this.radioButton1.Checked)
			{
				this.tbSzjs.Enabled = false;
				this.tbSzos.Enabled = false;
				return;
			}
			this.tbSzjs.Enabled = true;
			this.tbSzos.Enabled = true;
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine(this.Root, this.Node));
			this.xmlHelper.SelectNode(Path.Combine(this.Root, this.Node, this.ChildNode));
			this.xmlHelper.SetAttribute(this.LocationX, base.Location.X.ToString());
			this.xmlHelper.SetAttribute(this.LocationY, base.Location.Y.ToString());
			string value = this.tbJz.Text;
			this.xmlHelper.SetAttribute(this.strJzText, value);
			value = this.tbYz.Text;
			this.xmlHelper.SetAttribute(this.strYzText, value);
			value = this.cbYz.Text;
			this.xmlHelper.SetAttribute(this.strYzCbText, value);
			if (this.radioButton1.Checked)
			{
				value = "true";
			}
			else
			{
				value = "false";
			}
			this.xmlHelper.SetAttribute(this.strRd, value);
			value = this.tbSzjs.Text;
			this.xmlHelper.SetAttribute(this.strSzJsText, value);
			value = this.tbSzos.Text;
			this.xmlHelper.SetAttribute(this.strSzOsText, value);
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.tbJz.Text = "750";
			this.tbYz.Text = "750";
			this.cbYz.Text = "上/左";
			this.radioButton1.Checked = true;
			this.tbSzjs.Text = "750";
			this.tbSzos.Text = "750";
			if (!File.Exists(this.path))
			{
				return;
			}
			if (!this.xmlHelper.SelectNode(Path.Combine(this.Root, this.Node, this.ChildNode)))
			{
				return;
			}
			string attribute = this.xmlHelper.GetAttribute(this.LocationX);
			string attribute2 = this.xmlHelper.GetAttribute(this.LocationY);
			if (!string.IsNullOrEmpty(attribute) && !string.IsNullOrEmpty(attribute2))
			{
				base.Location = new System.Drawing.Point(Convert.ToInt32(attribute), Convert.ToInt32(attribute2));
			}
			string attribute3 = this.xmlHelper.GetAttribute(this.strJzText);
			if (attribute3 != null)
			{
				this.tbJz.Text = attribute3;
			}
			string attribute4 = this.xmlHelper.GetAttribute(this.strYzText);
			if (attribute4 != null)
			{
				this.tbYz.Text = attribute4;
			}
			string attribute5 = this.xmlHelper.GetAttribute(this.strYzCbText);
			if (attribute5 != null)
			{
				this.cbYz.Text = attribute5;
			}
			string attribute6 = this.xmlHelper.GetAttribute(this.strRd);
			if (attribute6 == "true" || attribute6 == null)
			{
				this.radioButton1.Checked = true;
			}
			else
			{
				this.radioButton2.Checked = true;
			}
			string attribute7 = this.xmlHelper.GetAttribute(this.strSzJsText);
			if (attribute7 != null)
			{
				this.tbSzjs.Text = attribute7;
			}
			string attribute8 = this.xmlHelper.GetAttribute(this.strSzOsText);
			if (attribute8 != null)
			{
				this.tbSzos.Text = attribute8;
			}
		}

		private void btOk_Click(object sender, EventArgs e)
		{
			if (!this.GetNumberBl(this.tbJz.Text))
			{
				this.tbJz.Focus();
				this.tbJz.Select(0, this.tbJz.Text.Length);
				YJKMessageBox.Show("布置点距次梁边偏移 必须是数字，请重新输入！");
				return;
			}
			if (!this.GetNumberBl(this.tbYz.Text))
			{
				this.tbYz.Focus();
				this.tbYz.Select(0, this.tbYz.Text.Length);
				YJKMessageBox.Show("偏移 必须是数字，请重新输入！");
				return;
			}
			if (!this.GetNumberBl(this.tbSzjs.Text))
			{
				this.tbSzjs.Focus();
				this.tbSzjs.Select(0, this.tbSzjs.Text.Length);
				YJKMessageBox.Show("奇数列中心左偏移 必须是数字，请重新输入！");
				return;
			}
			if (!this.GetNumberBl(this.tbSzos.Text))
			{
				this.tbSzos.Focus();
				this.tbSzos.Select(0, this.tbSzos.Text.Length);
				YJKMessageBox.Show("偶数列中心右偏移 必须是数字，请重新输入！");
				return;
			}
			this.SaveDlgData();
			base.DialogResult = DialogResult.OK;
		}

		private void btCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private bool GetNumberBl(string str)
		{
			double num = 0.0;
			return double.TryParse(str, out num);
		}

		private XmlHelperForElectric xmlHelper = new XmlHelperForElectric();

		private string path = SmokeFormConfigManager.m_strFullPath;

		private string Root = SmokeFormConfigManager.Root;

		private string Node = SmokeFormConfigManager.Node;

		private string ChildNode = SmokeFormConfigManager.ChildNode;

		private string LocationX = SmokeFormConfigManager.LocationX;

		private string LocationY = SmokeFormConfigManager.LocationY;

		private string strJzText = SmokeFormConfigManager.strJzText;

		private string strYzCbText = SmokeFormConfigManager.strYzCbText;

		private string strYzText = SmokeFormConfigManager.strYzText;

		private string strSzJsText = SmokeFormConfigManager.strSzJsText;

		private string strSzOsText = SmokeFormConfigManager.strSzOsText;

		private string strRd = SmokeFormConfigManager.strRd;
	}
}
